package cn.edu.scau.cmi.wujiaxian.exercise10;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.CharArrayReader;
import java.io.CharArrayWriter;
import java.io.IOException;


public class Example10_10 {
	
	//支持对内存的字节和字符读取操作(加快存储和读取的速度，当没办法长时间保存，可以用在克隆对象上）
	public static void main(String[] args) {
		try {
			ByteArrayOutputStream outByte = new ByteArrayOutputStream();
			byte[] byteContent = "国庆60周年".getBytes();
			outByte.write(byteContent);
			ByteArrayInputStream inByte = new ByteArrayInputStream(outByte.toByteArray());
			byte[] backBytes = new byte[outByte.toByteArray().length];
			inByte.read(backBytes);
			System.out.println(new String(backBytes));
			CharArrayWriter outChar = new CharArrayWriter();
			char[] charContent = "中秋快乐".toCharArray();
			outChar.write(charContent);
			CharArrayReader inChar = new CharArrayReader(outChar.toCharArray());
			char[] backChars = new char[outChar.toCharArray().length];
			inChar.read(backChars);
			System.out.println(new String(backChars));
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		
	}
	
}
